	var fieldJobId;
	var changeFromClick = false;
	//var reBackNodeText;
	
	//定位显示
	var arrayLi = [];
	var arrayLiInd = 0;
	$(document).ready(function(){
		$("#ff input").val("");
		//技术标准下拉框列表
		$('#comboxTechnicalStandard').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_KETTLE_JOB_TECH_STANDARD +'&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){/*
		    	alert('data:'+JSON.stringify(data));*/
		    	return data;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		
		//接口发送领域下拉框列表
		$('#comboxInterfaceSenderField').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllFields' +'?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data.content;
		    },
		    onSelect: function(record){
		    	comboxInterfaceSender.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: record.id},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findFieldSystemsByField' + '?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
        		    loadFilter: function(data){
        		    	return data.content;
        		    }
                }).load();
				$("#ff").data("changed",true);
		    },
		    onChange: function(newValue,oldValue){
		    	comboxInterfaceSender.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: newValue},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findFieldSystemsByField' +'?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
        		    loadFilter: function(data){
        		    	return data.content;
        		    }
                }).load();
		    }
		});
		
		
		//接口发送放数据源下拉框列表
		$('#comboxKettleDataSourceSend').combobox({
			url: BASE_URL_KETTLE_DATASOURCE_SEARCH + '/findAllKettleDataSource' +'?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	var result = [];
		    	if(data)
		    	{
		    		for(var i = 0; i < data.length; i++)
		    		{
		    			result.push({
		    				id: data[i].id,
				    		name: data[i].kettleDataSource.name
		    			});
		    		}
		    	}
		    	return result;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		
		//接口接收方数据源下拉框列表
		$('#comboxKettleDataSourceReceiver').combobox({
			url: BASE_URL_KETTLE_DATASOURCE_SEARCH + '/findAllKettleDataSource' +'?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	var result = [];
		    	if(data)
		    	{
		    		for(var i = 0; i < data.length; i++)
		    		{
		    			result.push({
		    				id: data[i].id,
				    		name: data[i].kettleDataSource.name
		    			});
		    		}
		    	}
		    	return result;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		
		
		//接口发送方下拉框列表
		var comboxInterfaceSender = $('#comboxInterfaceSender').combobox({
            disabled: true,
            valueField: 'id',
            textField: 'name',
            editable:false,
			onSelect:function(record)
			{
				$("#sencode").html(record.code);
		    	var data = $("#comboxInterfaceReceiver").combobox('getData');
		    	for(var i=0;i<data.length;i++){
		    		if(data[i].id==$("#comboxInterfaceReceiver").combobox('getValue')){
		    			$("#rescode").html(data[i].code);
		    			break;
		    		}
		    	}
		    	$("#bianma").html("ETL_"+$("#sencode").html()+"2"+$("#rescode").html()+"_");
		    	$("#bianma").attr("title","ETL_"+$("#sencode").html()+"2"+$("#rescode").html()+"_");
				$("#ff").data("changed",true);
			}
        });
		
		//接口接受领域下拉框列表
		$('#comboxInterfaceReceiverField').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllFields' +'?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data.content;
		    },
		    onSelect: function(record){
		    	comboxInterfaceReceiver.combobox({
	                disabled: false,
	                method:'get',
	                queryParams: {fieldId: record.id},
	                url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findFieldSystemsByField' +'?v=' + Math.random(),
	                valueField: 'id',
	                textField: 'name',
	    		    loadFilter: function(data){
	    		    	return data.content;
	    		    }
	            }).load();
				$("#ff").data("changed",true);
		    },
		    onChange: function(newValue,oldValue){
		    	comboxInterfaceReceiver.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: newValue},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findFieldSystemsByField' +'?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
        		    loadFilter: function(data){
        		    	return data.content;
        		    }
                }).load();
		    }
		});
		
		
		//接口接收方下拉框列表
		var comboxInterfaceReceiver = $('#comboxInterfaceReceiver').combobox({
            disabled: true,
            valueField: 'id',
            textField: 'name',
            editable:false,
			onSelect:function(record)
			{
		    	$("#rescode").html(record.code);
		    	var data = $("#comboxInterfaceSender").combobox('getData');
		    	for(var i=0;i<data.length;i++){
		    		if(data[i].id==$("#comboxInterfaceSender").combobox('getValue')){
		    			$("#sencode").html(data[i].code);
		    			break;
		    		}
		    	}
		    	$("#bianma").html("ETL_"+$("#sencode").html()+"2"+$("#rescode").html()+"_");
		    	$("#bianma").attr("title","ETL_"+$("#sencode").html()+"2"+$("#rescode").html()+"_");
				$("#ff").data("changed",true);
			}
        });
		
		
		//发送方数据库类型下拉框列表
		$('#comboxDatabaseTypeSender').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_DATABASE_TYPE +'&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		//接收方数据库类型下拉框列表
		$('#comboxDatabaseTypeReceiver').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_DATABASE_TYPE +'&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		
		//接口场景下拉框列表
	    $('#comboxInterfaceScan').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_KETTLE_JOB_INTERFACE_SCENE +'&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data;
		    },
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});
		
		$("#ff :input").bind('change',function() {
			$("#ff").data("changed",true);
		});
		$("#txtCreateDateTime").datebox({
			onSelect:function(record)
			{
				$("#ff").data("changed",true);
			}
		});    
	    //领域系统结构树
		var tree_id = '';
		var isSave = false;
		var modifyNode;
		//var reBackNode;
		
		$("#tt").tree({
			url:BASE_URL_TREE + '/getSystemInterfacesOfCurrentUserCanManageForEasyUiTree' +'?v=' + Math.random(),
			lines:false,
			onLoadSuccess:function()
			{
				$("#tt > li > ul > li > .tree-node > .tree-file, #tt > li > .tree-node > .tree-file").css("background","url('../../images/st_folder.png') 2px 2px no-repeat");
			},
			onBeforeSelect: function(node) {
				if($(node.target).children(".tree-folder").length)
				{
					return false;
				}
				if($(node.target).children(".tree-file").length && 
						($(node.target).parent().parent().parent().parent()[0].id == "tt" || 
								$(node.target).parent().parent()[0].id == "tt"))
				{
					return false;
				}
				return true;
			},
			onClick: function(node) {
				arrayLi = [];
				arrayLiInd = 0;
				changeFromClick = true;
				$("#systemName").val(node.text);
			},
			onSelect:function(node){
				if ($("#ff").data("changed")) {
					
					$.messager.confirm('温馨提示','<p>存在修改后未保存的数据,是否进行保存？<p>',function(r){
						if(r){
							isSave =  true;
							if(isSave){
								onSave();
								//reBackNode = node;
								//reBackNodeText = node.text;
								$("#ff").data("changed",false);
								if(node.nodeType == 'systemInterface'){
								
								fieldJobId = node.id;
								if(tree_id != fieldJobId)
								{
									tree_id = fieldJobId;
									$("#ff input").val("");
								}else
								{
									return false;
								}
								$.ajax({
					 				url: BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD +'/' + node.id  +'?v=' + Math.random(),
					 				dataType:'json',
					 				type:'get',
					 				contentType:"application/json",
					 				success:function(data){
					 					//alert("data:"+JSON.stringify(data));
					 					FormEcho(data);
					 					isSave =  false;
					 				},
					 				error:function(){
										$.messager.alert("错误","<p>服务异常，修改信息失败，请重新登录或稍后再试！</p>","error");	
					 					isSave =  false;
					 				}
					 				
					 				
					 			});
							}
						}
						}else{
								/*if(!(reBackNode === null))
								{
									$("#tt").tree('update',{
										target:reBackNode.target,
										text:reBackNodeText
									});
								}*/
								if(node.nodeType == 'systemInterface'){
								
								fieldJobId = node.id;
								if(tree_id != fieldJobId)
								{
									tree_id = fieldJobId;
									$("#ff input").val("");
								}else
								{
									return false;
								}
								$.ajax({
					 				url: BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD +'/' + node.id  +'?v=' + Math.random(),
					 				dataType:'json',
					 				type:'get',
					 				contentType:"application/json",
					 				success:function(data){
					 					//alert("data:"+JSON.stringify(data));
					 					FormEcho(data);
					 					isSave =  false;
					 				},
					 				error:function(){
										$.messager.alert("错误","<p>服务异常，查询信息失败，请重新登录或稍后再试！</p>","error");	
					 					isSave =  false;
					 				}
					 				
					 				
					 			});
							}
							//reBackNode = node;
							//reBackNodeText = node.text;
							$("#ff").data("changed",false);
						}
					});
				}
				if ($("#ff").data("changed")) {
					
				}else
				{
					//reBackNode = node;
					//reBackNodeText = node.text;
					/********************************************************/
					if (!$("#ff").data("changed"))
					{
						$("#ff").data("changed",false);
						if(node.nodeType == 'systemInterface'){
						$(".right_mask").css("display","none");
							fieldJobId = node.id;
							if(tree_id != fieldJobId)
							{
								tree_id = fieldJobId;
								$("#ff input").val("");
							}else
							{
								return false;
							}
							$.ajax({
				 				url: BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD +'/' + node.id  +'?v=' + Math.random(),
				 				dataType:'json',
				 				type:'get',
				 				contentType:"application/json",
				 				success:function(data){
				 					/*alert("data:"+JSON.stringify(data));*/
				 					FormEcho(data);
				 				},
				 				error:function(){
									$.messager.alert("错误","<p>服务异常，查询信息失败，请重新登录或稍后再试！</p>","error");	
				 				}
				 				
				 				
				 			});
						}
					}
					
					/************************************************************************************/
				}
			}
		});
		 
		
	});
	
	//保存
	function onSave(){
		/*var node = $('#tt').tree('getSelected');*/
		var JobId = $("#txtJobNameId").val();
		var jobName = $("#txtJobName").val();
		var jobCode = $("#bianma").html()+$("#txtJobCode").val();
		var tecStandard = $("#comboxTechnicalStandard").combobox('getValue');
		var senderDBType = $("#comboxDatabaseTypeSender").combobox('getValue');
		var receiverDBType = $("#comboxDatabaseTypeReceiver").combobox('getValue');
		var interfaceScene = $("#comboxInterfaceScan").combobox('getValue');
		var createTime = $("#txtCreateDateTime").datebox('getValue');
		var interfaceDesc = $("#txtAreaInterfaceDescription").val();
		var senderFieldSystem = $('#comboxInterfaceSender').combobox('getValue');
		var receiverFieldSystem = $('#comboxInterfaceReceiver').combobox('getValue');
		var sendKettleDataSource = $('#comboxKettleDataSourceSend').combobox('getText');
		var receiverKettleDataSource = $('#comboxKettleDataSourceReceiver').combobox('getText');
		if(senderFieldSystem == ""){
			$.messager.alert('警告',"<p>接口发送方不能为空！</p>","warning");
		}else if(receiverFieldSystem == ""){
			$.messager.alert('警告',"<p>接口接收方方不能为空！</p>","warning");
		}else{
		
			var jsonData = {
					id:JobId,
					jobCode:jobCode,
					jobName:jobName,
					tecStandard:tecStandard,
					createTime:createTime,
					interfaceScene:interfaceScene,
					interfaceDesc:interfaceDesc,
					senderDBType:senderDBType,
					receiverDBType:receiverDBType,
					senderFieldSystemId:$('#comboxInterfaceSender').combobox('getValue'),
					receiverFieldSystemId:$('#comboxInterfaceReceiver').combobox('getValue'),
					sendKettleDataSource:sendKettleDataSource,
					receiverKettleDataSource:receiverKettleDataSource
			};
			
			var systemInterfaceParam = JSON.stringify(jsonData);
			if($("#ff").form("validate")){
				$("#instance_save").linkbutton("disable");
				$("#instance_save .l-btn-text").text("提交中...");
				$.ajax({
					url:BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD + '/updateInterface',
					dataType:'json',
					type:'post',
					contentType:"application/json",
					data: systemInterfaceParam,
					success:function(data){
						if(data.backValue=='0'){
							$.messager.alert('提示',"<p>保存成功!</p>","info");/*
							$("#tt").tree('reload');*/
							/*$('#ff')[0].reset();*/
							$("#ff").data("changed",false);
							var node = $('#tt').tree('getSelected');
							if(!(node === null))
							{
								$("#tt").tree('update',{
									target:node.target,
									text:''+$('#txtJobName').val()+''
								});
							}
							$("#tt").tree('expandTo',node.target);
							$("#tt").tree('select',node.target);
							$("#instance_save").linkbutton("enable");
							$("#instance_save .l-btn-text").text("保存");
						}else{
							if(data.backValue == '1'){
								$.messager.alert('错误',"<p>保存失败,接口名称已存在!</p>","error");
							}
							if(data.backValue == '2'){
								$.messager.alert('错误',"<p>保存失败,接口编码已存在!</p>","error");
							}
							if(data.backValue == '3'){
								$.messager.alert('错误',"<p>保存失败,接口编码格式错误!</p>","error");
							}
							$("#instance_save").linkbutton("enable");
							$("#instance_save .l-btn-text").text("保存");
						}
					},
					error:function(xhr,s,err){
						$.messager.alert("错误","<p>服务异常，保存信息失败，请重新登录或稍后再试！</p>","error");	
						$("#instance_save").linkbutton("enable");
						$("#instance_save .l-btn-text").text("保存");
					}
					
					
				});
			}
		}
	}
	
	$("#searchNode").click(function (e) { 
		if($("#systemName").val() != '')
		{
			choose_tree();
		}else
		{
			//搜索关键字为空时，不进行搜索
			/*$("input").val("");
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');*/
			$(".tree_con").scrollTop(0);
		}
	});  
	$("#systemName").bind('input propertychange', function() {
		if(changeFromClick) {
			changeFromClick = false;
			return;
		}
		arrayLi = [];
		arrayLiInd = 0;
		if($("#systemName").val() != '')
		{
			choose_tree();
		}else
		{  //搜索关键字为空时，不进行搜索
			/*$("#ff input").val("");
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');*/
			$(".tree_con").scrollTop(0);
		}
	});
	$(document , "#systemName").keyup(function(event){
	  if(event.keyCode ==13){
	    $("#searchNode").trigger("click");
	  }
	});
	
	function getSelected()
	{
		var node = $('#tt').tree('getSelected');
		if(node.nodeType == 'systemInterface'){
			$.ajax({
				url: BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD +'/' + node.id + '?v=' + Math.random(),
				dataType:'json',
				type:'get',
				contentType:"application/json",
				success:function(data){
					FormEcho(data);
				},
				error:function(){
					/*alert("error");*/
				}
				
				
			});
		}
	}
	
	function choose_tree()
	{
		$('#tt').tree('expandAll');
		if(arrayLi.length == 0 && arrayLiInd == 0)
		{
			var searchVal = $("#systemName").val().toUpperCase(); 
			var row = $('#tt li .tree-node');  
			var rowcolumn = $('#tt li .tree-node > .tree-title');  
			var i = 0, j = 0;
			
			//row.removeClass('tree-node-selected');
			row.removeClass('tree-node-hover'); 
			rowcolumn.each(function (column) {  
				var matchVal = $(this).text(); 
				if(matchVal.indexOf(searchVal) != -1)
				{
					i++;
					var scrTop = $(".tree_con").scrollTop() + $(this).offset().top - 
						parseInt($(".tree_con").css("padding-top"),10) - 
						$(".search-con")[0].offsetHeight - $(".left_menu > .menu_tit")[0].offsetHeight;

					if(i <= 1)
					{
						//$(this).parent().addClass('tree-node-selected'); 
						$(this).parent().addClass('tree-node-hover'); //改成鼠标hover状态，不选中搜索结果

						$(".tree_con").scrollTop(scrTop);
						arrayLiInd = 1;
						//getSelected();
					}				
					arrayLi.push([matchVal,scrTop]);
				}
				}); 
			}else
			{
				var rowcolumn = $('#tt li .tree-node > .tree-title'); 
				var row = $('#tt li .tree-node');  
				//row.removeClass('tree-node-selected');
				row.removeClass('tree-node-hover'); 
				if(arrayLiInd <  arrayLi.length)
				{
					rowcolumn.each(function (column) {  
						var matchVal = $(this).text(); 
						if(matchVal == arrayLi[arrayLiInd][0])
						{
							//$(this).parent().addClass('tree-node-selected'); 
							$(this).parent().addClass('tree-node-hover'); //改成鼠标hover状态，不选中搜索结果
							$(".tree_con").scrollTop(arrayLi[arrayLiInd][1]);
							arrayLiInd++;
							//getSelected();
							return false;
						}
					});
				}else
				{
					//arrayLi = [];
					arrayLiInd = 0;
					$(".tree_con").scrollTop(0);
					choose_tree();
				}
			}
	}
	//表单数据回显
	function FormEcho(data){
		$("#sencode").html("");
		$("#rescode").html("");
		$("#bianma").html("");
		$("#txtJobNameId").val(data.id);
		$("#txtJobName").val(data.jobName).validatebox('validate');
		if(data.jobCode){
			$("#txtJobCode").val(data.jobCode.substr(-3));
			$("#bianma").html(data.jobCode.replace(data.jobCode.substr(-3),""));
			$("#bianma").attr("title",data.jobCode.replace(data.jobCode.substr(-3),""));
		}else{
			$("#bianma").html("ETL_发送方编码2接收方编码_？？？");
			$("#bianma").attr("title","ETL_发送方编码2接收方编码_？？？");
		}
		$("#comboxTechnicalStandard").combobox('setValue',data.tecStandard);
		if(data.tecStandard==null){
			$("#comboxTechnicalStandard").combobox('setValue','2');
		}
		$("#comboxInterfaceSenderField").combobox('setValue',data.senderFieldSystem_fieldId);
		$("#comboxInterfaceReceiverField").combobox('setValue',data.receiverFieldSystem_fieldId);
		$("#comboxInterfaceSender").combobox('setValue',data.senderFieldSystemId);
		$("#comboxInterfaceReceiver").combobox('setValue',data.receiverFieldSystemId);
		$("#comboxDatabaseTypeSender").combobox('setValue',data.senderDBType);
		$("#comboxDatabaseTypeReceiver").combobox('setValue',data.receiverDBType);
		$("#comboxInterfaceScan").combobox('setValue',data.interfaceScene);
		$("#comboxKettleDataSourceSend").combobox('setValue',data.sendKettleDataSource);
		$("#comboxKettleDataSourceReceiver").combobox('setValue',data.receiverKettleDataSource);
		if(data.interfaceScene==null){
			$("#comboxInterfaceScan").combobox('setValue','2');
		}
		$("#txtCreateDateTime").datebox('setValue',data.createTime);
		$("#txtAreaInterfaceDescription").val(data.interfaceDesc);
		
		
		$("#comboxTechnicalStandard").siblings(".textbox").children(".textbox-text").val($("#comboxTechnicalStandard").combobox('getText'));	
		$("#comboxInterfaceSenderField").siblings(".textbox").children(".textbox-text").val($("#comboxInterfaceSenderField").combobox('getText'));
		$("#comboxInterfaceReceiverField").siblings(".textbox").children(".textbox-text").val($("#comboxInterfaceReceiverField").combobox('getText'));
		$("#comboxInterfaceSender").siblings(".textbox").children(".textbox-text").val($("#comboxInterfaceSender").combobox('getText'));
		$("#comboxInterfaceReceiver").siblings(".textbox").children(".textbox-text").val($("#comboxInterfaceReceiver").combobox('getText'));
		$("#comboxDatabaseTypeSender").siblings(".textbox").children(".textbox-text").val($("#comboxDatabaseTypeSender").combobox('getText'));
		$("#comboxDatabaseTypeReceiver").siblings(".textbox").children(".textbox-text").val($("#comboxDatabaseTypeReceiver").combobox('getText'));
		$("#comboxInterfaceScan").siblings(".textbox").children(".textbox-text").val($("#comboxInterfaceScan").combobox('getText'));
		$("#txtCreateDateTime").siblings(".textbox").children(".textbox-text").val($("#txtCreateDateTime").combobox('getText'));
	}
	
	function jumpSend(){
		var title = "领域系统数据源管理";
		var param = $("#comboxKettleDataSourceSend").combobox("getText");
		var url = "/pages/LedgerManagement/FieldSystemDataSourceManage.html?name=" + param;
		var icon=$(this).attr("icon");
		window.parent.OpenTab(title,url,icon, true);
	}
	
	function jumpReceiver(){
		var title = "领域系统数据源管理";
		var param = $("#comboxKettleDataSourceReceiver").combobox("getText");
		var url = "/pages/LedgerManagement/FieldSystemDataSourceManage.html?name=" + param;
		var icon=$(this).attr("icon");
		window.parent.OpenTab(title,url,icon, true);
		
	}


/*$('#txtJobName').bind('input propertychange keyup', function() {
	var node = $('#tt').tree('getSelected');
	if(!(node === null))
	{
		$("#tt").tree('update',{
			target:node.target,
			text:''+$('#txtJobName').val()+''
		});
	}
});*/
